Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Reimplement Coraza-SPOA #103

Open
wants to merge 6 commits into
base: main
Choose a base branch
from
Open

Reimplement Coraza-SPOA #103

wants to merge 6 commits into from

Conversation

fionera
Copy link

@fionera fionera commented Feb 18, 2024

Another go at updating coraza-spoa to a the up to date coraza version and a faster spop library. It also uses upstream e2e tests


Q: Why rewrite instead of incremental changes?
A: I didn't had time nor motivation to figure out why some things are how they are. It was just easier to do it like this.


TODOs:

  • Config files
  • Allow listening to a unix-socket
  • Correct logger setup
  • Figure out how to work with errors inside the handler
  • Fixup docker containers

Other PRs that are similar:

Closes #84 #85 #90 #88 #75

@fionera fionera marked this pull request as draft February 18, 2024 21:46
@fionera fionera requested a review from sts February 18, 2024 21:53
jptosso
jptosso previously approved these changes Feb 19, 2024
@jptosso jptosso self-requested a review February 19, 2024 08:23
with:
go-version: '1.21'

- name: setup environment
Copy link
Member

@jcchavezs jcchavezs Feb 19, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd really avoid going in this direction, this assumes a haproxy is running in local which is going to be a big friction to those willing to contribute. Personally I would never install haproxy locally to debug a problem so I suggest we spin up a haproxy instance using docker with testcontainers api (see https://pkg.go.dev/github.com/testcontainers/testcontainers-go) or just docker-compose so the test is selfcontained and does not assume I have something installed.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I explicitly did this without using containers (atleast inside the CI) as its faster to run. Locally and in production I would always recommend running without docker as the performance difference is huge.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(Also I dont have docker on my machine since its just very slow on macos)

Copy link
Member

@jcchavezs jcchavezs Feb 20, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I really prefer to have something that is portable. It is OK if we want CI to run haproxy locally but we also need to provide a way to run it with docker. Again here we prioritize user experience if I have to install locally haproxy to contribute I'd rather not contribute hence we use containers. For advanced users they can definitively use local haproxy.

"github.com/dropmorepackets/haproxy-go/pkg/testutil"
)

const directives = `
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please use go:embed for this, also in general we would like to keep a consistent http e2e suite by suing https://github.com/corazawaf/coraza/tree/main/http/e2e which is being used in coraza http handler, caddy and coraza-proxy-wasm. Running it is as easy as spin up an instance and run a go command, see https://github.com/corazawaf/coraza-caddy/blob/main/magefile.go#L74

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why should I use embed for a single string? Inside the coraza tests its done the same way.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But yeah I can migrate the e2e tests to run the command but I am not a fan of running commands and basically ignoring the go test framework. If the Upstream would properly expose the tests as a list we could run these in parallel and reduce testing times while also reducing the amount of external dependencies

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I opened an issue on coraza itself to expose this and make it easier for other repos to use the e2e test suite.
corazawaf/coraza#1006

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Waiting for a coraza release to fix this up

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe it is better you use master for now.

internal/application.go Outdated Show resolved Hide resolved
Copy link
Member

@jcchavezs jcchavezs left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looking good, I added a few comments and I also think we are missing some unit tests, specifically for functions around parsing request elements. Great work!

@fionera fionera force-pushed the rewrite branch 3 times, most recently from ee4e7f7 to f0db161 Compare February 19, 2024 19:39
@fionera
Copy link
Author

fionera commented Feb 25, 2024

Sorry that I didn't update on this again but I am currently working on getting a talk done. Will try to get the other points done by the end of next week

@fionera
Copy link
Author

fionera commented Mar 11, 2024

I think this can be reviewed and tested now. There is still a fd leak when reloading and changing the logger, also when there is a reload with logger change and then an a reload that reverts this, the old file can be raced. There should probably a small wrapper around the logger to provide prevent multiple writers to the same file, but I guess this can wait.

@fionera fionera marked this pull request as ready for review March 11, 2024 00:58
@fionera fionera requested a review from jcchavezs March 11, 2024 00:58
@fzipi
Copy link
Member

fzipi commented Jun 12, 2024

@fionera Can you solve the conflicts here?

@fionera
Copy link
Author

fionera commented Jun 14, 2024

Sure will do that

@fionera
Copy link
Author

fionera commented Jun 21, 2024

Updated :)

This allows us to not rely on the http header,
but instead use a variable inside the transaction.
This does leak fds as the logging target never gets closed,
this has to be fixed before release but this will work for now.
It is not correctly configured anyway and
we have go specific linters enabled
I don't know why I didn't just close it after leaving the function.
There is no other use of the fd...
@fionera
Copy link
Author

fionera commented Jun 21, 2024

And now without missing to remove an old file 🗡️

@csuka
Copy link

csuka commented Jul 28, 2024

Yeah, can we ensure this gets approved/merged?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants